1

I have an iframe on my webpage that contains a linked qwebirc webchat that automatically logs visitors into irc with a temporary nick so all page visitors can instantly chat with each other.

I need to switch from qwebirc to kiwi irc, but it doesn't support autoconnecting.

** It will be connecting to our own irc server and I understand the risk of automatically joining visitors.

Since we cannot install a custom kiwi irc installation to our web server and customize it to autojoin, I know that I'll need to use a jquery function to automatically click the start button on the linked widget in the iframe.

Here is an example of what I'm working with:

<html>
    <head>
        <title></title>
    </head>
    <body bgcolor="#000000" link="#FFFFFF" vlink="#FF0000" alink="#FFA500">
        <center>
        <font face="tahoma" color="#FFFFFF">The "Start..." button below needs to be automatically clicked on page visit.</font>
        <br><br>
        <iframe src="https://kiwiirc.com/client/irc.MYCHATSERVER.net:6660/?nick=TESTNAME-?&theme=mini#TESTCHANNEL" height="400" width="400"></iframe>
        </center>
    </body>
</html>

(our server and channel have been renamed for this post, so it shouldn't actually connect)

I know that the function we need to use is:

$(document).ready(function(){
$('#some-id').trigger('click');
});

but I can't seem to find the id of the button.. the only thing I can find is the following line:

<button type="submit">Start...</button>

..that I found here: https://i.sstatic.net/zK7Xi.jpg

I'm not very good with javascript, but am a very willing learner and have a bit of a problem to solve. Any advice on how to incorporate the jquery code is greatly appreciated.

Thanks!!!

2 Answers 2

1

You will not be able to interact with elements inside the iframe using scripts from the parent document, or vice versa. This is a security measure and not something you can circumvent.

The same-origin policy restricts how a document or script loaded from one origin can interact with a resource from another origin.

See Same-origin policy

Sign up to request clarification or add additional context in comments.

4 Comments

how about sending keystrokes blindly to the iframe? If the start button is the first button by default, can ENTER be sent to the iframe to simulate the user striking the enter key?
JavaScript does not allow you to send keystrokes to the iframe, or any part of the document, blindly or otherwise. The best you would normally be able to do is trigger the handler that would respond to a user event, not actually create the event itself. Obviously this will also not work if the iframe falls foul of the same-origin purpose. I have to say I find the idea of interacting with a third party page on "behalf" of your user - however benign the intention - falls short of the "don't be evil" test.
Consider this, you have just sold something to the user. In order to do a bit of free marketing, you open iframes to Twitter and Facebook and - if the user is signed in to those domains (which is reasonably likely) post on their behalf to say how much "they" have enjoyed your services. Saves them the effort. Why even both with a credit card service, just open a iframe to their bank website and initiate the bank transfer on their behalf - saves effort again. This may be an extreme example, but demonstrates why the same origin policy exists and why it should be impossible to work around.
as stated in my original post, I completley understand why this policy is in place. In terms of my intentions passing the evil test, we're talking about my own irc server taking on the load, and potential risk, of site visitors automatically logging in. The functionality is already in place with qwebirc, and my users are pushing for the feature to be retained when the widget is switched. For now.. we'll work out a solution.. as you said, there's no real option this way. Thanks for your help though!!
0

I took a look at the IRC page and noticed that the button that needs to be clicked—<button type="submit">Start...</button>—is always the first button on the page. Therefore, you can use the following code to click it:

$("button").first().click()

note: Concerning what pwdst said, you cannot script cross-domain (by default). However, this jQuery library may very well be worth looking into.

2 Comments

The OP will not be able to interact with any elements inside the iframe - see my answer
@pwdst If they aren't the same domain, yeah, he can't interact with it. However, I think that library might work for him.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.