JavaScript - Apending Images With The Width & Height Attr In Ie
Hey guys i am test my page in IE8 and i have a small problem
the following script works in other browsers but not IE8 Code: function preload(arrayOfImages) { $(arrayOfImages).each(function () { $('<img />').attr('width', '100px').attr('height', '100px').attr('src',this).appendTo('#img').attr('class', 'img'); setTimeout(this, 2000); }); } when i run this with lets say 100 images and all the image sizes are all diffrent and above 150px*150px when this runs it will preload the images fine BUT it loads the images with their defualt width & height and not 100px*100px any idea why this is? Similar TutorialsHello, let me try to explain better what I'm trying to do. I'm a real newbie I don't know much javascript but I understand more or less the logic behind it... tell me if this solution should work and if you know how to do it please show me. I have this page. http://felixdeportu.com/5/ The images are inside a div#content div#photo. I need to make div#photo's width to match the total width measurement of all the images it contains. If you load the page and you don't touch the size, it will work fine... but that's not realistic. If I resize the page, which will happen often on this kind of page (I'm assuming), the whole thing goes haywire (try it, scroll to the last image and resize the page you'll see what I mean). What can I do? Is my idea the right solution? Am I not explaining this clearly enough? Let me know please, I'm desperate. I've been trying to get CSS to do this for me for 3 hours now. Nothing works... End result: I want to have buttons along the top of a textarea which will be used to add tags around highlighted text / the text curser thingy. (Basically it will be an edit box like the I am using now to make this post). Problem at the moment: I want to reference the var to use in the function. e.g. Code: function addtext(id) { var al = "<div style=\"text-align:left;\"></div>"; document.myform.outputtext.value += id; } "id" will be defined as "al" in the HTML onclick function, I want this to use "var al" where it says ".value += id;". HTML: Code: <form name="myform"> <textarea name="inputtext">Type Here</textarea><br /> <textarea name="outputtext"></textarea><br /> <input type="button" value="Add New Text" onClick="addtext(al);"> </form> If I do this: onClick="addtext('al'); Then "al" is just written in the output box as it is sending a string, correct? If I do this: onClick="addtext("al"); / onClick="addtext(al); Then nothing happens... Reason I want to do it: Well, because I want to have multiple var's instead of a load of functions... Problem 2 (To fix after first problem): I also want the var to add around the highlighted text, not after all of the text. Hi My html document contain many images which has the attribute src of img tag as the flowing : PHP Code: http://images.mysite.com/a/p/ap.eba553af4b719.ec03.jpg?x=210&y=83&q=85&sig=Tua1ukyUEVKTPSsz7xGPsg-- All those images has the common source folder http://images.mysite.com/a/p This is an example : PHP Code: <img src = "http://images.mysite.com/a/p/ap.eba553af4b719.ec03.jpg?x=210&y=83&q=85&sig=Tua1ukyUEVKTPSsz7xGPsg--" width = "105" height = "73" > I tried during many days to find the solution using RegExp but I didn't arrives. What I want to do is I - change for all image from the seem folder the src attribute to match the exact url of the image without special characters, for this example : PHP Code: http://images.mysite.com/a/p/ap.eba553af4b719.ec03.jpg?x=210&y=83&q=85&sig=Tua1ukyUEVKTPSsz7xGPsg-- Became : PHP Code: http://images.mysite.com/a/p/ap.eba553af4b719.ec03.jpg II - Control the width and height of the image by changing its height and width attributes resp. from two javascript variables : PHP Code: var v_width = 320 // Just for example var v_height = 250 // Just for example This is an example of try didn't work for me, for the first issue : PHP Code: var element = document.getElementsByTagName("img"); for(var i=0;i<element.length;) { var myString = new String(); var myRegExp = new RegExp("http:\/\/d\.images\.mysite\.com\/a\/p[^\?]*(jpg|png|gif)","i"); var myRegExp0 = new RegExp("\?.*","i"); myString = element[i].getAttribute("src"); if(myRegExp.test(myString)) { var newString = myString.replace(myRegExp0,""); element[i].setAttribute("src",newString); } } Help me please Think you Hello guys ! I'm fairly new to JavaScript, so this is maybe an obvious mistake, but here is the code that doesn't work, it goes inside the body of my document : Code: <script type="text/javascript"> aImg = new Image(); aImg.src = "myimage.jpg"; aHeight = aImg.height; aWidth = aImg.width; document.write(aHeight + "," + aWidth); document.write("<img src=" + aImg.src + ">"); </script> While the image is displayed, the value written for the height and width is "0". This code worked fine when I compiled it in the "Tryit Editor" of w3schools.com (I told you I was new to JS :P), but it fails when I insert it in a page and then view the page with Google Chrome or IE7. Of course this is not all fo the code, I intend to display the image differently depending of its size... but I need to get that part right before moving on Any help would be greatly apreciated, thanks ! Hi I have embeded a video like this: Code: <div class="videoDiv" id="showDis"> <object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" id="MediaPlayer1"> <param name="url" value="http://mysite/myvideo.wmv""> <param name="src" value="http://mysite/myvideo.wmv""> <param name="showcontrols" value="true"> <param name="autostart" value="true"> <!--[if !IE]>--> <object type="video/x-ms-wmv" data="http://mysite/myvideo.wmv""> <param name="src" value="http://mysite/myvideo.wmv""> <param name="autostart" value="true"> <param name="controller" value="true"> </object> <!--<![endif]--> </object> </div> I would like to retrieve the video's width and height (resolution), for example: 640x480 how can I do that via JavaScript? this is what I tried: Code: var objPlayer = document.MediaPlayer1; alert(objPlayer.offsetWidth); alert(objPlayer.width); alert(document.getElementById('showDis').style.width); alert(document.getElementById('showDis').style.offsetWidth); nothing gives me the real value. even looked he http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx but couldn't find anything relevant I have embeded a video like this: Code: <div class="videoDiv" id="showDis"> <object classid="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" id="MediaPlayer1"> <param name="url" value="http://mysite/myvideo.wmv""> <param name="src" value="http://mysite/myvideo.wmv""> <param name="showcontrols" value="true"> <param name="autostart" value="true"> <!--[if !IE]>--> <object type="video/x-ms-wmv" data="http://mysite/myvideo.wmv""> <param name="src" value="http://mysite/myvideo.wmv""> <param name="autostart" value="true"> <param name="controller" value="true"> </object> <!--<![endif]--> </object> </div> I would like to retrieve the video's width and height (resolution), for example: 640x480 how can I do that via JavaScript? this is what I tried: Code: var objPlayer = document.MediaPlayer1; alert(objPlayer.offsetWidth); alert(objPlayer.width); alert(document.getElementById('showDis').style.width); alert(document.getElementById('showDis').style.offsetWidth); nothing gives me the real value. even looked he http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx but couldn't find anything relevant Hi guys, was just wondering if there was a way to control the page height and width using js/jquery? I have a page that is: width: 980px height: 2500px I would like the page height to be set to around 900px with the viewable scrollbar and all other content not viewable underneath. Any help is appreciated Cheers, paffley Hi, well earlier i asked for a script which can load game which showing some banner until the game is loading and the load progress that it shows, it shouldn't be fake, many people said you need flash for it, but atlast i found a script that can do that for me. BUT there is a issue when i started using the script in the script the width and height can be in px like width 500 but it can't be made to width 100% when i make it 100% the script stops working. I can't use px or any other thing except 100% as i want the flash to increase its width and height with the change in screen resolution. Here is the script, you can make a demo html file out of it for testing purposes, if you don't want to make one i am ready to provide a demo page too, please leave a comment for it. Thank you ^_^ Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Pre-roll Example page</title> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script> <script type="text/javascript" src="http://files.cryoffalcon.com/woro/preroll.dev.js"></script> <style> .gamecontent {width:923px;padding:0px;margin:0px auto 0px auto;background-color:#FFF;} .gamecontent .gamewrapper {margin:0px auto 0px auto;} .gamecontent .game {float:left;margin:0px auto 0px auto;padding:0px;overflow:hidden;width:1px;height:1px} .gamecontent .ad {display:none;width:300px;height:300px;margin:0px auto 0px auto;padding:50px auto 0px auto;text-align:center;font-size:10px} .gamecontent .ad #progress {width:200px;height:10px;margin:10px auto 0px auto;padding:0px;border:solid 1px #E7B9D1;text-align:left;} .gamecontent .ad #pbar {width:0px;height:10px;background-color:#CCC;} .gamecontent .ad #pskip {text-align:center;} .medrectangle {width:300px;height:250px;border:none} </style> </head> <body> <div class="gamecontent"> <div class="gamewrapper" style="height:640px;width:640px;"> <div class="game" id="gameframe"></div> <div id="adframe" class="ad"> <div>Advertisement</div> <div id="plad"></div> <div id="progress"></div> </div> <noscript> <div> <!--Game embed code should be placed here here--> </div> </noscript> </div> </div> <script type="text/javascript" language="javascript"> var af = 'adframe'; var gf = 'gameframe'; var gid = 'gameswf'; var adinvoke = '<iframe class="medrectangle" src="<!--to show my logo or ad-->" scrolling="no"></iframe>'; function skipad() { $('#plad').html('<div></div>'); $('#'+af).hide(); $('#'+gf).css('width','640px'); $('#'+gf).css('height','640px'); } $('#gameframe').preloadad( { // calls the init method swf : 'http://games.balloontowerdefense.net/b/balloon_tower_defense_4_expansion.swf', width : 640, height : 640, gameid : gid, gameframe : gf, adframe : af, adcode : adinvoke, pltime : 10000, gametype : 'swf', base :'http://games.balloontowerdefense.net/b/', skiptxt : 'Click here to show the game', showad :'1' }); </script> </body> </html> in the above code the 640 width and height is the issue, as it doesn't work with 100% values, i was wondering how to make it work with 100% width and height. I don't know what did i miss or where did i go wrong? I am trying to customize this scrollbar so that it will fit all screen resolutions and I was wondering how I could do this by somehow customizing the JavaScript files created by Nathan Faubion or if I could do this using other JavaScript variables (var widthPercentage) to change the pixels to percentages? Please let me know what you think. Thank you very much! One of the pages on the website I'm using the JavaScript on: http://www.clintshipley.com/about.html Code: JavaScript file jsScroller.js: //Created by Nathan Faubion http://www.n-son.com/scripts/jsScrolling/ function jsScroller (o, w, h) { var self = this; var list = o.getElementsByTagName("div"); for (var i = 0; i < list.length; i++) { if (list[i].className.indexOf("scroller-content") > -1) { o = list[i]; } } //Private methods this._setPos = function (x, y) { if (x < this.viewableWidth - this.totalWidth) x = this.viewableWidth - this.totalWidth; if (x > 0) x = 0; if (y < this.viewableHeight - this.totalHeight) y = this.viewableHeight - this.totalHeight; if (y > 0) y = 0; this._x = x; this._y = y; with (o.style) { left = this._x +"px"; top = this._y +"px"; } }; //Public Methods this.reset = function () { this.content = o; this.totalHeight = o.offsetHeight; this.totalWidth = o.offsetWidth; this._x = 0; this._y = 0; with (o.style) { left = "0px"; top = "0px"; } }; this.scrollBy = function (x, y) { this._setPos(this._x + x, this._y + y); }; this.scrollTo = function (x, y) { this._setPos(-x, -y); }; this.stopScroll = function () { if (this.scrollTimer) window.clearInterval(this.scrollTimer); }; this.startScroll = function (x, y) { this.stopScroll(); this.scrollTimer = window.setInterval( function(){ self.scrollBy(x, y); }, 40 ); }; this.swapContent = function (c, w, h) { o = c; var list = o.getElementsByTagName("div"); for (var i = 0; i < list.length; i++) { if (list[i].className.indexOf("scroller-content") > -1) { o = list[i]; } } if (w) this.viewableWidth = w; if (h) this.viewableHeight = h; this.reset(); }; //variables this.content = o; this.viewableWidth = w; this.viewableHeight = h; this.totalWidth = o.offsetWidth; this.totalHeight = o.offsetHeight; this.scrollTimer = null; this.reset(); }; JavaScript on HTML page: <script type="text/javascript" src="Scripts/jsScroller.js"></script> <script type="text/javascript" src="Scripts/jsScrollbar.js"></script> <script type="text/javascript"> var scroller = null; var scrollbar = null; window.onload = function () { scroller = new jsScroller(document.getElementById("scroller"), 550, 275); scrollbar = new jsScrollbar (document.getElementById("scrollbar-content"), scroller, false); } </script> Hello, I run a online gaming website, and I'm having problems with certain websites iframing our games. Actually I'm ok with iframing, as long as they include the banner ad located just beneath our games. But often times unscrupulous webmasters will iframe only the game, preventing us from generating any revenue from the banner ad (and costing us additional bandwidth charges). I'm hoping to find a way to detect the dimensions of the iframe, so that I may dynamically resize the game, in order to include the banner ad within the iframe. Does anybody know how to extract the "height" and "width" attribute values from an <iframe> tag sitting on a different site? Regards, Steve I want to set the width of a div to be the same width of the image inside the div. The following code works great. But... The images are different widths, so both wrappers are set to the width of the first image. Without having to add an ID to each wrapper or image, can the wrapper width be set to the image width using the name of the image as the unique identifier? Any help would be great! PHP Code: jQuery: $(document).ready(function(){ var newWidth = $('div.wrapper img').attr('width'); $('div.wrapper').width(newWidth); }); HTML: <div class="wrapper"> <p><img src="image1.jpg" width="200" /><br /> Caption</p> </div> <div class="wrapper"> <p><img src="image2.jpg" width="250" /><br /> Caption</p> </div> Hi, I need to re-size a div to be 100% of the browser but taking into account the height of an existing header div. Currently it works but it doesn't factor the height of the above header div, and therefore scrolls off the page (the height of the header div) I need to manipulate ( subtract the height value of the header) in the javascript somehow. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <script type="text/javascript"> function SetHeightOfDiv(){ var theDiv = document.getElementById('content'); theDiv.style.height = BrowserHeight()+"px"; } function BrowserHeight() { var theHeight; if (window.innerHeight) { theHeight = window.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { theHeight = document.documentElement.clientHeight; } else if (document.body) { theHeight = document.body.clientHeight; } return theHeight; } </script> </head> <body style="height:100%; background-color:blue; margin:0; padding:0; color:#ffffff; font-size:15px; text-align:center; font-family:monospace,arial" onload="SetHeightOfDiv()"> <div id="wrapper" style="height:100%; width:900px; background-color:yellow; margin-left:auto; margin-right:auto; overflow:hidden"> <div id="header" style="margin-top:0px; height:130px; width:890px; margin-left:5px; background-color:red; position:fixed"> <p>The FIXED HEADER</p> </div> <div id="content" style="margin-top:132px; background-color:grey; width:890px; margin-left:5px"> <p>THE BODY - that extends below the browser window (possibly the height of the header)</p></br> <p>So how do we manipulate the Javascript to 'Subtract' the height of the HEADER?</p></br> <p style="text-align:left; padding-left:10px"> function SetHeightOfDiv(){ <br> var theDiv = document.getElementById('content');<br> theDiv.style.height = BrowserHeight()+"px";<br> }<br> </br> function BrowserHeight() {<br> var theHeight;<br> if (window.innerHeight) {<br> theHeight = window.innerHeight;<br> }<br> else if (document.documentElement && document.documentElement.clientHeight) {<br> theHeight = document.documentElement.clientHeight;<br> }<br> else if (document.body) {<br> theHeight = document.body.clientHeight;<br> }<br> return theHeight;<br> }</p> </div> </div> <!--end of wrapper--> </body> </html> Thanks Need to set the width of a Table that is being spit out by this god awful CMS... please help me... change the html attribute width! Hi there, I've been searching for an answer to this for the last few days but with no luck, so I thought I'd register here to see if anyone can possibly help. All I've been able to find everywhere for this is examples of changing images when rolling over them or clicking them, and I don't need that. What I need is a bit of javascript that will recognise some image paths on a page and replace those image paths with other ones. It's for an ecommerce website on a certain platform, using a customer reviews section which outputs star images based on the customer's rating. So, the images used (which look awful) are, for example, "sourcehere/stars_5.gif", "sourcehere//stars_4.gif", and so on. Just 5 of them. I want to design my own 5 images, upload those images, and then have the javascript replace the rubbish looking ones on the page with my own images. I thought I'd be able to find something quite easily, but so far all I can find is examples of mouseover events and so on, and I don't need any of that, just the entire image replaced with my own image. Can anyone help please? I'm a beginner with javascript so I'll need it spelled out to me! Thankyou for your time. Hey everyone! I'm in the process of creating a portfolio site for my artwork and I'm requesting help. The website has a scalable JQuery background which changes depending on which thumbnail you click. I've uploaded the progress he http://www.aldousmassie.com/newprogress I'm using this code at the moment to scroll through the background: Code: <!-- SCRIPT FOR CHANGING BG ON CLICK --> <script type="text/javascript"> imgs=Array("img/00.jpg","img/01.jpg","img/02.jpg","img/03.jpg"); var x=0; function change() { document.getElementById("bgimg").src=imgs[++x]; if (x==3) { x=-1; } } if (!imgs[x+1]) { x=-1; } </script> <!-- SCRIPT BELOW OVERWRITES SCRIPT ABOVE --> <script type="text/javascript"> imgs=Array("img/08.jpg","img/09.jpg","img/10.jpg","img/11.jpg","img/12.jpg","img/13.jpg"); var x=0; function change() { document.getElementById("bgimg").src=imgs[++x]; if (x==5) { x=-1; } } if (!imgs[x+1]) { x=-1; } </script> Unfortunately, the bottom code overwrites the top. Is it possible for each different background image to have their own "set" of images that could be scrolled through onclick? I'd appreciate any tips that point me in the right direction. Thank you. Please help have a look at the scripts... Where's gone wrong that whenever an image fades out into 0, it reappears before another image comes out? I've wanted to make the image disappear shortly before a new image is loaded. I've worked on this and played around with the scripts, yet no finding... Please do tell me if you know the answer to it. Thanks. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script> window.onload = function(){ var pic = document.getElementById("pic"); document.getElementById("nextImageFading_btn").onclick = function(){nextImageFading();} } var img = new Array(); img[0] = "http://www.blogsdna.com/wp-content/uploads/2011/03/Google-labs.png"; img[1] = "http://thenextweb.com/socialmedia/files/2010/07/youtube_logo.png"; img[2] = "http://www.techlifeweb.com/facebook_logo.jpg"; img[3] = "http://hackingarticles.com/wp-content/uploads/gmail_logo_stylized.png"; var o = 100; var t; var p = 0; var f = 1; function nextImageFading(){ t = setInterval( function(){ pic.src = img[p]; pic.style.filter = "alpha(opacity="+o+")"; pic.style.MozOpacity = o/100; pic.style.opacity = o/100; o -= 1; if(o<=0){ clearInterval(t); if(p<img.length-1){ p = p+1; } else {p=0;} pic.src = img[p]; pic.style.filter = "alpha(opacity=100)"; pic.style.MozOpacity = 1; pic.style.opacity = 1; o = 100; } },f); } </script> </head> <body> <img id="pic" src="" style="width:400px; height:400px;" /> <br style="clear:both;" /> <a id="nextImageFading_btn" href="#">NEXT</a> </body> </html> I have a the following code for displaying a tooltip: Code: <a style='margin-left: 10px; position:relative' class="tooltip" title="This is some text to display"> The javascript for the tooltip is as follows: Code: $(document).ready(function(){ $("a.tooltip").live( { mouseenter: function(e){ this.t = this.title; this.title = ""; $("body").append("<p id='tooltip'>"+ this.t +"</p>"); $("#tooltip") .css("top",(e.pageY - 10) + "px") .css("left",(e.pageX + 20) + "px") .fadeIn("fast"); var css_width = $('#tooltip').width(); var text_width = $('#tooltip').textWidth(); if (css_width > text_width) { $('#tooltip').width(text_width); } }, mouseleave: function(){ this.title = this.t; $("#tooltip").remove(); } } ); }); $.fn.textWidth = function textWidth() { var html_org = $(this).html(); var html_calc = '<span>' + html_org + '</span>'; $(this).html(html_calc); var width= $(this).find('span:first').width(); $(this).html(html_org); return width; } What I want to do is to be able to add another variable 'width' to be able to set the width of the tooltip like so: Code: <a style='margin-left: 10px; position:relative' class="tooltip" width="100" title="This is some text to display"> This width will then be passed into the javascript above and used to set the width of the tooltip. How can I modify the above code to do this?? Thanks Hi, I'd like to set the div width equal to the image width. Here's what I can think of: Code: <script type="text/javascript"> window.onload = function () { document.getElementById('foo').style.width = document.getElementById('bar').width + 'px'; } </script> <div id="foo" style="background:red;"><img id="bar" src="image.jpg"></div> It seems to be working, but I'm not sure if it's correct coding. Thanks in advance for checking the code or any improvement you suggest! Rain lover |