Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Doing Object Method from onclick function (or update HTML in iFrame)

Featured Replies

I'm not all that great with Javascript and I might just be having a dense but I can't work out how to run an object method from a jQuery event handler.

var myObject = Object.create(Parser);
myObject.init();
myObject.registerEvents();

$("#button").click( myObject.registerEvents );

What the function does is copy the html in a textarea into an iFrame.

Alternatively finding a way to update the rendering in the iFrame of the changed textarea's HTML.

1 hour ago, PinkHammer said:

What the function does is copy the html in a textarea into an iFrame.
 

You want to be really careful with that, it can put you at risk of XSS attacks.  somebody could just dump a link to a malicious script right in that.

56 minutes ago, PinkHammer said:

I'm not all that great with Javascript and I might just be having a dense but I can't work out how to run an object method from a jQuery event handler.


var myObject = Object.create(Parser);
myObject.init();
myObject.registerEvents();

$("#button").click( myObject.registerEvents );

What the function does is copy the html in a textarea into an iFrame.

Alternatively finding a way to update the rendering in the iFrame of the changed textarea's HTML.

The click method is deprecated in newer versions of jQuery, you should use .on() method instead. The reason why your code isn't working, is because the first argument to .click is a callback, where you can pass in a parameter to capture the event.

$('#button').click(function(e) {
  console.log(e)
})

Here's an example of what you're trying to do, but it's extremely dangerous. Like @rbrtsmith said, any malicious script in the textarea could be injected directly into the frame. You can try this yourself by dropping <script>alert()</script> into the textarea and submitting.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.