add javascript to content inside iframe

Hi,

I have a drupal 7 site where I use h5p module.

How could I add external js file inside the iframe where the interactive content is (question set)?

I have managed to modify the embed.php file, and that works when the interactive content is embedded manually to a page.

But I think the embed.php file is not used when the h5p content is shown normally on a interactive content page.

Is there a file like embed.php which to modify to add a javascript?

The script which I need to add in the iframe is google analytics tracking script.

Thank you for a great module.

otacke's picture

Hi Jukka79!

Scripts can be added in h5p.js. You're modifying the core of H5P here, so I hope you are sure what you're doing.

Cheers,
Oliver

I've been trying to disable the right-click context menu in the audio player. I added this code to the end of h5p.js:

jQuery(document).ready(function(){
  jQuery(function() {
        jQuery(this).bind("contextmenu", function(event) {
            event.preventDefault();
            alert('Right click disable in this site!!')
        });
    });
});

I've verified this code works-- everywhere in the frame except in the audio player. I did test it elsewhere successfully.

I also tried adding oncontextmenu="return false;" to the audio tag in debug mode as below. that works but I don't see how to change that in h5p

<audio class="h5p-audio" controls="" preload="auto" style="display: block; width: 100%;" oncontextmenu="return false;"><source src="pathto.mp3" type="audio/mp3"></audio>

Any thoughts how to get there form here?  thanks.

i have h5p plugin in moodle
i want to disalble right click on interactive video
i found the file h5p.js  and can edit it ,  but  where to add this code please

where?

I noted in my post abopve exactly where

"I added this code to the end of h5p.js:"

the end means the end. the very end after everything else.

otacke's picture

:-D

I noted in my post abopve exactly where

"I added this code to the end of h5p.js:"

the end means the end. the very end after everything else.

Currently, the h5p audio player has a settings option to disable downloads. It doesn't work because the h5p audio player uses the native browser html5 audio player for playback. This could be fairly easily remedied. Add some code to the h5p audio content type that when "Allow Download" under "Display Options " in the settings is unchecked and saverd, then these parameters are added to the audio player

oncontextmenu="return false;" 

and

controls controlsList="nodownload"

for example:

<audio width="640" controls controlsList="nodownload" oncontextmenu="return false;"> <source data-src="talktalk.mp3" type="audio/mp3"></audio>

I have tested this and it does work, just needs to be implemented. Looking for a h5p developer to take this on. I'm sure it would serve many people want to block downloads directly from the page displayed. (Yes, I know people can still scour the source and find the URL)

thanks