| | |
new window? target="_blank" ?
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I want random links in this code to open in a new window. how to please ?
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<script language="JavaScript"> <!-- // Create arrays to contain all the values // for links and image locations link = new Array image = new Array link[1]="http://www.wildexpo.com.au/Aust%20Rep%20Show/" image[1]="http://www.reptilesaustralia.com.au/forums/Ads/wildexpo.gif" link[2]="http://www.excite.com" image[2]="http://www.excite.com/mesp/images/excite/new_logo-180.gif" link[3]="http://www.lycos.com" image[3]="http://a284.g.akamai.net/7/284/987/000/lygo.com/ly/i/lyguide.gif" link[4]="http://www.cnet.com" image[4]="http://cnet.com/Images/Headers/cnet-1-title.gif" link[5]="http://www.webcrawler.com" image[5]="http://webcrawler.com/img/web/hdr/home_header.gif" // Create a random number between 1 and five random_num = (Math.round((Math.random()*4)+1)) // Write a link and images with random array document.write("<a href=\"" + link[random_num] + "\">"); document.write("<img src=\"" + image[random_num] + "\" border=\"0\"></a>"); --> </script>
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
target = "_blank" should work.
change:
to
change:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
document.write("<a href=\"" + link[random_num] + "\">");
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
document.write("<a href=\"" + link[random_num] + "\" target=\"_blank\">");
Plato forgot the nullahedron..
Not Quite Resolved!
Whats wrong with back slash? The code works in testbed but wont cop the backslash on my board (ipb) ?
Whats wrong with back slash? The code works in testbed but wont cop the backslash on my board (ipb) ? JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
document.write("<a href=\"" + link[random_num] + "\" target=\"_blank\">"); document.write("<img src=\"" + image[random_num] + "\" border=\"0\"></a>");
Always carry a flagon of whiskey in case of snakebite and furthermore always carry a small snake.
W. C. Fields
W. C. Fields
•
•
•
•
Not Quite Resolved!Whats wrong with back slash? The code works in testbed but wont cop the backslash on my board (ipb) ?
[/code]
try either:
document.write("<a href=\\"" + link[random_num] + "\\" target=\\"_blank\\">");
document.write("<img src=\\"" + image[random_num] + "\\" border=\\"0\\"></a>");
(double backslash should be escaped to backslash by your board software which can then go on to be the javascript escape character when the page is rendered)or (my prefered way):
document.write('<a href="' + link[random_num] + '" target="_blank">');
document.write('<img src="' + image[random_num] + '" border="0"></a>');
(all literal strings in the Javascript are quoted with single quote characters, and attributes in the dynamically created elements are quoted with double quote characters :- escaping doesn't matter) Last edited by MattEvans; Feb 14th, 2007 at 2:53 pm.
Plato forgot the nullahedron..
![]() |
Similar Threads
- Backlinks with target="_blank" (Search Engine Optimization)
- google "keyword" question (Search Engine Optimization)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Center Div in Browser
- Next Thread: Reference to undefined property FIREFOX
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp animate array automatically beta box bug calendar cart checkbox class codes column cookies createrange() css cursor date debugger decimal design dom download dropdown editor element embed enter error events explorer firefox focus frameworks getselection google gwt hint html htmlform ie7 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp listbox maps masterpage math menu microsoft mimic mp4 object onmouseover parent paypal php player position post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search select session shopping size sql text textarea toggle variables w3c webservice website window windowofwords windowsxp wysiwyg







