SitePoint Sponsor |
|
User Tag List
Results 1 to 9 of 9
-
Feb 14, 2008, 02:19 #1
- Join Date
- Aug 2007
- Location
- Brighton, UK
- Posts
- 2,006
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Open Link in new window - then open other link in the same window!
I have three 'help' links. I want them to all open in new windows/tabs.
But, if the new 'help' window had already been opened I want the other links, if they are clicked on, to use that window.
So at anytime, only two windows will be open...
Is this possible? ... Does anyone know how to do it?
Thank you★ James Padolsey
–––––––––––––––––––––––––––––––––––––––
Awesome JavaScript Zoomer (demo here)
'Ajaxy' - Ajax integration solution (demo here)
-
Feb 14, 2008, 03:41 #2
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
Code Javascript:if (!window.['helpWindow']) { // create help window } // use help window
Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
-
Feb 14, 2008, 05:02 #3
- Join Date
- Aug 2007
- Location
- Brighton, UK
- Posts
- 2,006
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you pmw57... but I am no JS wiz...
Could you take me through exactly how I would open a new window with the name of 'helpwindow' and then use that window if it is already open...?
Thank you★ James Padolsey
–––––––––––––––––––––––––––––––––––––––
Awesome JavaScript Zoomer (demo here)
'Ajaxy' - Ajax integration solution (demo here)
-
Feb 14, 2008, 05:11 #4
- Join Date
- Aug 2007
- Location
- Brighton, UK
- Posts
- 2,006
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Actually nevermind I think I have it....
One thing though - How do I change the location in the already opened window?★ James Padolsey
–––––––––––––––––––––––––––––––––––––––
Awesome JavaScript Zoomer (demo here)
'Ajaxy' - Ajax integration solution (demo here)
-
Feb 14, 2008, 06:32 #5
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
Code Javascript:// Create new window window.helpWindow = window.open('', 'helpWindow'); // Window now referenced as window.helpWindow or window['helpWindow'] // Redirect the window window.helpWindow.location.href = 'http://www.google.com';
Extra for experts: What purpose does the 'helpWindow' name in the open method serve?Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
-
Feb 14, 2008, 07:12 #6
- Join Date
- Aug 2007
- Location
- Brighton, UK
- Posts
- 2,006
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
THANK YOU!! - I have it working now!
Anyway - I have another problem now - I don't think it is worth starting another thread...
Why does this not work???
Code JavaScript:window.onload = function1('uilink1'); function function1(linkid) { var thelink = document.getElementById(linkid); var location = thelink.getAttribute('href'); alert(location); }
Code HTML4Strict:<a href="http://www.google.com" id="uilink1">Link 1</a>
★ James Padolsey
–––––––––––––––––––––––––––––––––––––––
Awesome JavaScript Zoomer (demo here)
'Ajaxy' - Ajax integration solution (demo here)
-
Feb 14, 2008, 11:05 #7
- Join Date
- Nov 2004
- Location
- Nelson BC
- Posts
- 2,310
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Because this line:
window.onload = function1('uilink1');
assigns the return value of function1('uilink1') to window.onload. But what you really want is to assign that function to onload, so use:
window.onload = function () {function1('uilink1');};
If there were no parameters you could do
window.onload = function1;
-
Feb 14, 2008, 11:53 #8
- Join Date
- Aug 2007
- Location
- Brighton, UK
- Posts
- 2,006
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks jimfraser - it works perfectly now, plus I learnt something
★ James Padolsey
–––––––––––––––––––––––––––––––––––––––
Awesome JavaScript Zoomer (demo here)
'Ajaxy' - Ajax integration solution (demo here)
-
Feb 14, 2008, 12:44 #9
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
And if you were going to use the function only once, you could use an anonymous function.
Code Javascript:window.onload = function () { var linkid = 'uilink1'; var thelink = document.getElementById(linkid); var location = thelink.getAttribute('href'); alert(location); }
Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript
Bookmarks