You must Sign In to post a response.
  • Category: JavaScript

    Getting the id from previous tab using local storage

    I want to pass the audio id from one tab to another tab to control the audio in the previous tab from the dynamically opened new tab using keydown events.Below is my actual code which controls the audio with keydown event when i am that tab

    <asp:TemplateField HeaderText="Play Audio File" ItemStyle-Width="200px" ItemStyle-HorizontalAlign="Center" >
    <ItemTemplate>
    <audio controls="controls" id="player">
    <source src='<%# Eval("audio") %>' />
    your browser does not support the audio element.</audio>
    </ItemTemplate>
    </asp:TemplateField>


    <script type = "text/javascript">
    var audio = document.getElementById("player");

    window.addEventListener("keydown", playPauseKb, false);

    function playPauseKb(event) {
    var x = event.keyCode;
    console.log(x);
    if (x == 120) {
    audio.currentTime -= 5;//F9 Rewined
    }

    else if (x == 122) {
    //event.data.$.preventDefault();
    audio.currentTime += 5;//F11 forword
    }

    else if (x == 121) {
    if (audio.paused) {
    audio.play();//F10 paly/pause
    }
    else {
    audio.pause()
    }
    }

    }
    </script>

    <script type = "text/javascript">
    $(document).ready(function () {
    CKEDITOR.on('instanceCreated', function (e) {
    e.editor.on('contentDom', function () {
    e.editor.document.on('keydown', function (event) {
    if (event.data.$.keyCode == 120) {
    event.data.$.preventDefault();
    audio.currentTime -= 5;//f10_Rewind
    }

    else if (event.data.$.keyCode == 122) {
    event.data.$.preventDefault();
    audio.currentTime += 5;//F11 farward
    }
    else if (event.data.$.keyCode == 121) {
    event.data.$.preventDefault();
    if (audio.paused) {
    audio.play();//f6_play and pause
    }
    else {
    audio.pause()
    }
    }
    });

    });
    });
    });

    </script>

    To this the local storage that is used is

    <script type="text/javascript">
    var audioElement = document.getElementById(player);
    if (typeof (Storage) !== "undefined") {
    localStorage.setItem("audiourl", audioElement);
    document.getElementById("result").innerHTML = localStorage.getItem["audiourl"];
    }
    </script>

    But its not working i am new to the concept of local storage can any one help me out
  • #770445
    The way you are reading is wrong also you are assigning the object to the innerHTML which may throw exception, try like below

    var audioElement = document.getElementById(player);
    if (typeof (Storage) !== "undefined") {
    localStorage.setItem("audiourl", audioElement);
    document.getElementById("result").innerHTML = localStorage.getItem("audiourl").value();

    The localStorage object stores data with no expiration date.

    The data is not deleted when the browser is closed, and are available for future sessions

    Thanks!
    B.Ramana Reddy


  • Sign In to post your comments