Javascript cross window interaction - javascript

I have this very simple Javascript to write on a text area when the link is clicked:
<head>
<script language="javascript" type="text/javascript">
function addtext(text) {document.form.textarea.value = document.form.textarea.value+= text;}
</script>
</head>
<body>
<form action="" method="" name="form">
<textarea name="textarea" rows="" cols="" wrap="wrap"></textarea>
</form>
q
</body>
Now I want to up the ante.
What I want to do is have the form in another another window, and that when I click the link, I writes to a textarea in another window.
I'm not necessarily asking for the code because I realize this might be quite complicated.
The question would be where to start, because I havenĀ“t got a clue!!
(when I Google cross window or cross domain interaction with Javascript I don't really get anything useful).
So any help I can get, libraries, plugins or whatever might guide me in the right direction is more than appreciated.

Ok, I wrote you a sample you can check at http://jsfiddle.net/zzdAL/
$(document).ready(function()
{
popup = window.open("http://fiddle.jshell.net");
$("#input1").click(function() {
try {
popup.document.window.alert(1);
}
catch (e) { alert(e.message); }
});
}
);
It only runs an alert on the popup, but you can do whatever you want with the popup, assuming you have the necessary rights (needs to be the same domain I believe).
The most simple is to write a function in your popup and call it from the opener.

Probably it's too late, but here is an example of interaction: window interaction

Take a look to greasemonkey, it's an addon for your browser.
You can choose on which page(s) the script will works.
http://wiki.greasespot.net/Main_Page

Related

Auto Click on hyperlink

I would like to a HTML code with the following functions if you guys can help , please.
Once the page loads, after 1 second to auto click on a hyperlinked text , how do I do this ? For the new website to be opened in the same window.
I have this code but this one is sending me to a new window and the pop up is blocking - not good
<!DOCTYPE html>
<html>
<body>
<head>
<script>
function autoClick(){
document.getElementById('linkToClick').click();
}
</script>
</head>
<body onload="setTimeout('autoClick();',700);">
<a id="linkToClick" href="http://www.google.com" target="_blank">GOOGLE</a>
</body>
</body>
</html>
Thanks
Instead of using <a href=> you should try just setting the variable window.location.href. So your code should look something like this:
<body onload="window.location.href='http://www.google.com',700);">
https://www.w3schools.com/howto/howto_js_redirect_webpage.asp
Let me preface this by saying this is extremely questionable when it comes to web design, and generally regarded as a shady or bad practice. That said:
$(window).on('load', function(){
window.location = 'http://example.com'
});
OR (vanilla JS)
window.onload = function(){ window.location = 'http://example.com' };
Again, be careful with this. If you want to do something like this, you need a pretty good reason why.
Possible duplicates:
Redirect from an HTML page
HTML redirect on page load

Code clears page instead of going to new site

I've been trying to create this chrome extension that you enter an address and click a button and it goes there. This may sound like a stupid idea but somehow a server block on a site is bypassed by chrome extensions. This is my current code:
<html>
<head>
<title>Website Opener</title>
<style type="text/css">
body
{
font-family: "Lucida Grande";
height: 100%;
}
</style>
<script>
$(document).ready(function() {
$('#url').change(function() {
var newurl = $('#url').val();
$('a.target').attr('href', newurl);
});
});
</script>
</head>
<body>
<form>
<input type="text" id='url' value='http://'>
<br>
<p><a class="target" href="">Go!</a></p>
</form>
</body>
</html>
What it currently does is just make the page blank or clear the input box instead of going to the new site.
I have tried javascript .open() method, this is trying jQuery. I'm mainly wondering if there are any other ways to do this or if I'm missing something.
This will help you:
Place jQuery to your <head> or in the end of your page, but before your code.
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>
Then rewrite your code to use a keypress event:
$(document).ready(function() {
$('#url').keypress(function() {
$('.target').attr('href', this.value)
})
});
FYI: change event will happen when you changed a value of your input and set the focus out of it. So if you type an url and place your mouse cursor on the link and press it, change event will trigger AFTER your click. So be careful with those events.
UPDATE:
I just saw that you're doing an extension for GC.
The best practices tell us to divide application by layers' aim. HTML and JS should be separated.
In your manifest.json you have to add
"js": ["jquery.js", "content_script.js"]
and move your JavaScript logic from HTML file to the content_script.js.

How to open popups automatically after certain time (without blocking)

I am making a web page, in which I have to open a popup window from an buton after 8 seconds(8000 ms).
I want to put some delay(8 seconds) before a popup open automatically.
my problem is that mozilla firefox block my popup
Here is my code:
<html>
<head>
<script>
function call()
{
popup = window.open('http://www.google.co.in');
}
function caller()
{
setInterval(call, 8000);
}
</script>
</head>
<body>
<input type="button" onclick="caller();">
</body>
</html>
There is no way around a browser's popup blocking/displaying architecture. All you can do is call the JS method. What happens then is outside the HTML/JS purview.
Javascript popups are really kind of out of fashion on the web, because of the blockers. They're annoying, their behavior depending on device is unpredictable, and generally, users hate them. Consider another approach.
You should use the function setTimeout(functionName , delay) instead of setInterval. setInterval will popup a new window every 8 seconds while setTimeout will only do it once.
<html>
<head>
<script>
function call()
{
popup = window.open('http://www.google.co.in');
}
setTimeout(call, 8000);
</script>
</head>
<body>
<input type="button" onclick="caller();">
</body>
</html>
And I'm agree, look for an another way to do what you want. Popups are often a inconvenience for users, especially for partially-sighted person.
By default many web browser block automatic popup. They only alow popup for direct action like in an onClick envent.

How to Open a Hyperlink (2) in the same window which was opened with a click to Hyperlink1

I am working on a requirement with a (Parent) web page having some links suppose Link1,Link2 and Link3.when i click Link1 which will be opened in a new window which is active window1 (child) and when i click Link2/Link3 the page should open in the same window (window1) .
Question:
Is there a way in Javascript/Jquery/Ajax to implement this functionality.Please do share your valuable thoughts on this.
Note:
If none of the links are opened then a new window should pop up. I know that we have Option target="_blank/_self/_top" etc in HTML.
You want to create your own named window.
Just add target="SomeName" to all of the links, and they will reuse the named window if it still exists.
Since you have asked the JS/ jQuery way,
JavaScript way is,
window.open('http://www.example.org','window1');
<html>
<head>
<script>
function open_win(url)
{
window.open(url,"hello","",true);
}
</script>
</head>
<body>
Google <br>
Yahoo <br>
Gmail
</body>
</html>
Issue is resolved thanks,i Thought too much / some thing else which lead this misconception. Thanks

Modal dialog options

I am opening a window as a modal.
window.showModalDialog("http://www.google.com","","dialogWidth:500px;dialogHeight:500px")
as I set height, what are other options available?
Like option buttons, menus etc. where I can find tutorials?
EDIT
It works in Mozilla firefox, but people are saying it doesn't!
My code is
Please somebody Edit my sample code for display purpose
<html>
<head>
<script>
function abc() {
window.showModalDialog("3.htm", "", "dialogWidth:500px;dialogHeight:500px");
}
</script>
</head>
<body>
<input type="button" id="check" name="check" onclick="abc()" value="open"/>
</body>
</html>
Second EDIT
code for page 3.htm
<html>
<head>
<script>
function abc(){
close()
}
</script>
</head>
<body>
<input type="button" id="check" name="check" onclick="abc()" value="close"/>
</body>
</html>
Check out both code on fire fox! and tell me.
Third EDIT
Ok It's not working in corme and opera
Be aware that showModalDialog is IE specific and won't necessarily work with other browsers. If you want cross browser modal dialogs you need to use a div to hide the rest of the page and overlay your dialog on top. It is easier to use an existing javascript library that already takes care of this.
I suggest not to use popups in web apps. Use floating divs instead which looks like a modal dialog but are better than the popups.
JQuery UI has a decent popup/modal dialog API and I've worked with the Boxy plugin which is very easy to implement.
They're cross browser and simple to use.
To load a page using boxy use:
var boxyPopup;
Boxy.load("aPage.html",
{title: "Title",
modal: true,
fixed: false,
afterShow: function(){
boxyPopup = this;}});
I'm not sure what you mean by it not opening a new page on same boxy window but using the above you have the boxyPopup var as a reference to the open boxy object and can access/change contents using that.

Categories

Resources