after I done my previous script (with a little big help of Padonak & Kor)
I'm asking for help with other Javascript
well I want to add some html code to a DIV, and the code includes a link obtained with Javascript.
The problem is when I execute the script the page goes to another with only the html code that I had add and the code present in the DIV where the code was added.
javascript:URL = document.getElementById("IMG to get URL").getElementsByTagName("img")[0].src; document.getElementById("DIV to add the HTML code...").innerHTML += '<center><input type="button" value="text button" onClick="window.open("URL","popup title","height=400, width=200");"></input></center>';
what's wrong with this?? , and why the page gets white and only with the DIV where the code was been added...
Rather than placing this inline, I suggest you create a function and call this in the link tag.
Also, why do you have "URL" in the javascript string? Shouldn't it be "onclick"?
FYI
* My screen resolution is set at 1680x1050
* I'm accessing your site through a T1 line
* I'm probably viewing it using Firefox (unless browser is specified)
Rather than placing this inline, I suggest you create a function and call this in the link tag.
Also, why do you have "URL" in the javascript string? Shouldn't it be "onclick"?
it gets the url: document.getElementById("IMG to get URL").getElementsByTagName("img")[0].src
and this should add the HTML code to the page but it redirects to a page with only the DIV I want to add the HTML code...:
document.getElementById("DIV to add the HTML code...").innerHTML +=
yap, I'm using in line because I'll add this script to a favorite of my browser, thats why I'm doing in line...
javascript:void(document.getElementById("DIV to add the code").innerHTML += '<script type="text/javascript">var URL=document.getElementById("DIV to get image URL").getElementsByTagName("img")[0].src;</script><center><input type="button" value="button text" onClick="javascript:window.open("URL","popup", "height=400, width=200");"></input></center>' );
the problem now is with the link of the button :S which doesn't work
maybe is a error with the javascript code creating the variable URL, IDK...
javascript:void(document.getElementById("DIV to add the code").innerHTML += '<script type="text/javascript">var URL=document.getElementById("DIV to get image URL").getElementsByTagName("img")[0].src;</script><center><input type="button" value="button text" onClick="javascript:window.open("URL","popup", "height=400, width=200");"></input></center>' );
Where do you put that? In an onclick attribute? Elsewhere? Would you paste whole tag please?
The first problem is with quotes inside the strings - your "main" string is single-quoted ('<script...'), inside of which there are double-quoted strings (like "DIV to add the code", "img" etc.), but the last of those ("window.open...") contain another sub-strings ("popup", "height...") which can't be specified without escaping their quote characters.
The other problem is with the "URL" part - you're providing "URL" as the string "URL", not the value of the URL variable. This should work fine:
Code:
document.getElementById("DIV to add the code").innerHTML += '<script type=text/javascript>
var URL=document.getElementById("DIV to get image URL").getElementsByTagName("img")[0].src;</script><center>
<input type="button" value="button text" onclick="javascript:window.open(URL,\'popup\', \'height=400, width=200\');" />
</center>';
And few more things (about the generated HTML): it's better to use "onclick" instead of "onClick", and the proper would be "<input />" rather than "<input>", but those last aren't so important in your case.
The first problem is with quotes inside the strings - your "main" string is single-quoted ('<script...'), inside of which there are double-quoted strings (like "DIV to add the code", "img" etc.), but the last of those ("window.open...") contain another sub-strings ("popup", "height...") which can't be specified without escaping their quote characters.
The other problem is with the "URL" part - you're providing "URL" as the string "URL", not the value of the URL variable. This should work fine:
Code:
document.getElementById("DIV to add the code").innerHTML += '<script type=text/javascript>
var URL=document.getElementById("DIV to get image URL").getElementsByTagName("img")[0].src;</script><center>
<input type="button" value="button text" onclick="javascript:window.open(URL,\'popup\', \'height=400, width=200\');" />
</center>';
And few more things (about the generated HTML): it's better to use "onclick" instead of "onClick", and the proper would be "<input />" rather than "<input>", but those last aren't so important in your case.
yap, there is a problem with the URL, I changed the variable "URL" to "_URL" and happened the same
javascript:void(document.getElementById("DIV to add the code...").innerHTML += '<script type=text/javascript>
var iohwe=document.getElementById("Image URL").getElementsByTagName("IMG")[0].src;</script><center>
<input type="button" value="button text" onclick="javascript:window.open(iohwe,\'popup\', \'height=400, width=200\');" />
</center>' );
how could I get the link to the image and open the image in the popup?
Bookmarks